<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import = "support.*, java.util.*, java.sql.*;"%>

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Graduate School Application</title>
	<script type="text/javascript" src="entry.js"></script>
</head>
<body >
<%	
	Connection conn = null;
	PreparedStatement stm = null;
	ResultSet result = null;

	try {
		Class.forName("org.postgresql.Driver");
		conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/Graduate_application_database", "postgres", "postgres");
	
		conn.setAutoCommit(false);
		
		stm = conn.prepareStatement("SELECT * FROM countries_and_states WHERE is_country");
		result = stm.executeQuery();
		
		conn.commit();
		conn.setAutoCommit(true);
				
		Student student = new Student();
		session.setAttribute("student", student);
	%>
	
	<h3>Please enter in your information:</h3>
	
	<form method = "GET" action="address.jsp" onsubmit="return validate()">
		First Name: <input type = "text" name = "firstname" id="fname"/><br/>
		Middle Name: <input type = "text" name = "middleinitial" id="mname"/><br/>
		Last Name: <input type = "text" name = "lastname" id="lname"/><br/>

		Country:
		 <select style =" width:150px;" name = "country" >
		 	<%	while(result.next()) {%>
				<option value=<%=result.getInt("cs_id") %>> <%= result.getString("country_state") %> </option>
			<%  } %>
		</select> <br/>
		<input type = "submit" value = "Submit" name = "submit" />
	</form>
	
	
	
<% 
		result.close();
		stm.close();
		conn.close();
	}
	catch (SQLException e)
	{
		throw new RuntimeException(e);
	}
    finally {
        if (result != null) {
            try {
                result.close();
            }
            catch (SQLException e) { }
            result = null;
        }
        if (stm != null) {
            try {
                stm.close();
            } 
            catch (SQLException e) { }
            stm = null;
        }
        if (conn != null) {
            try {
                conn.close();
            } 
            catch (SQLException e) { }
            conn = null;
        }
    }
%>	

</body>
</html>